package com.zyh.scs.admin.base.open;

import com.zyh.scs.admin.api.constant.open.CodeSet;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author hwh
 *
 * @param <T>
 */
@Data
@ToString
public class LaoSheDateResponse<T> implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	protected Integer errCode;

	protected String errMsg;

	protected String traceId;

//	protected Long Timestamp;
//
//	protected Long centerTime;

//	protected T data;

	public LaoSheDateResponse(){
		this.errCode = CodeSet.SYSTEM_EXCEPTION.getCode();
		this.errMsg = "处理失败";
		this.traceId = "";
	}

	public LaoSheDateResponse(Integer code, String msg, String traceId){
		this.errCode = code;
		this.errMsg = msg;
		this.traceId = traceId;
	}
	
	public static <T> LaoSheDateResponse<T> success(String msg, String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setErrMsg(msg);
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheDateResponse<T> successData(T object, String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setErrMsg("处理成功");
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheDateResponse<T> successRollBackRecharge(String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setErrMsg("处理成功");
		result.setTraceId(traceId);
//		result.setTimestamp(System.currentTimeMillis());
		return result;
	}

	public static <T> LaoSheDateResponse<T> successCheck(T object, String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setErrMsg("处理成功");
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheDateResponse<T> error(CodeSet codeSet, String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(codeSet.getCode());
		result.setErrMsg(codeSet.getCodeName());
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheDateResponse<T> error(Integer errCode, String errMsg, String traceId){
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(errCode);
		result.setErrMsg(errMsg);
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheDateResponse<T> error() {
		LaoSheDateResponse<T> result = new LaoSheDateResponse<>();
		result.setErrCode(CodeSet.SYSTEM_EXCEPTION.getCode());
		result.setErrMsg("系统处理失败");
		result.setTraceId("");
		return result;
	}

	public void setCodeSet(CodeSet codeSet) {
		this.setErrCode(codeSet.getCode());
		this.setErrMsg(codeSet.getCodeName());
		this.setTraceId("");
	}

}